package org.example.acm;

import java.util.Scanner;

/**
 * 题目描述
 * 给出数字K,请输出所有结果小于K的整数组合到一起的最少交换次数。
 * 组合一起是指满足条件的数字相邻，不要求相邻后在数组中的位置。
 *
 * 数据范围：
 *
 * 100 <= K <= 100
 *
 * 100 <= 数组中数值 <= 100
 * 输入描述
 * 第一行输入数组：1 3 1 4 0
 *
 * 第二行输入K数值：2
 */
public class SwapCountSolution {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] nums = scanner.nextLine().split(" ");
        int k = scanner.nextInt();
        int res = getSwapCount(nums, k);
        System.out.println(res);
    }

    public static int getSwapCount(String[] nums, int k) {
        int[] prefixSumArr = new int[nums.length + 1];
        int smallCount = 0;
        for (int i=0;i<nums.length;i++) {
            int compare = Integer.parseInt(nums[i]);
            if (compare < k) {
                smallCount++;
                prefixSumArr[i+1] = prefixSumArr[i] + 1;
            } else {
                prefixSumArr[i+1] = prefixSumArr[i];
            }
        }
        if (smallCount <= 1) {
            return 0;
        }
        int maxZoneCount = 0;
        for (int i=0;i+smallCount-1<nums.length;i++) {
            maxZoneCount = Math.max(maxZoneCount, prefixSumArr[i+smallCount] - prefixSumArr[i]);
        }
        return smallCount - maxZoneCount;
    }
}
